<%@ page import="grame.AppSetting; grame.SystemUserName; org.apache.shiro.SecurityUtils" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<g:applyLayout name="application">
<!--[if lt IE 7 ]> <html lang="zh_CN" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="zh_CN" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="zh_CN" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="zh_CN" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="zh_CN" class="no-js"><!--<![endif]-->
<head>
    <g:set var="userName" value="${SecurityUtils.subject?.principal?.toString() ?: SystemUserName.Anonymous.name()}"/>
    <g:set var="appName" value="${params.appName ?: (AppSetting.findByName('default.app.name') ?: 'Grame')}"/>
    <g:set var="skinName" value="${params.skinName ?: (AppSetting.findByName('default.skin.name') ?: 'grame')}"/>
</head>

<body>
<div class="container">
    <div class="row">
        <!-- Fixed navbar -->
        <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar"
                            aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="${createLink(uri: '/')}">
                        <span>${appName}</span>
                    </a>
                </div>

                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <g:pageProperty name="page.navbar"/>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <g:pageProperty name="page.navbar-right"/>
                        <li class="hidden">
                            <a href="JavaScript:void(0);"><span class="glyphicon glyphicon-user" aria-hidden="true" title="${userName}"></span></a>
                        </li>
                        <li class="hidden">
                            <a href="${createLink(controller: 'auth', action: 'login', params: [targetUri: params.targetUri])}"><span class="glyphicon glyphicon-log-in" aria-hidden="true"></span></a>
                        </li>
                        <li class="hidden">
                            <a href="${createLink(controller: 'auth', action: 'signOut')}"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span></a>
                        </li>
                    </ul>
                </div><!--/.nav-collapse -->
            </div><!-- /.container -->
        </nav>
    </div>
</div>

<g:layoutBody/>

<div class="container">
    <!-- Begin footer -->
    <div class="row">
        <footer class="panel-footer">
            <p class="text-center">${AppSetting.findByName('ICPRegistrationRecord')}</p>

            <p class="text-center">&copy; Grame 2015-${new Date().format('yyyy')}</p>
        </footer>
    </div>
    <!-- Ajax spinner -->
    <div id="spinner" class="spinner" style="display:none;">Loading&hellip;</div>
</div>

<content tag="script">
    <script type="text/javascript">
        $(function () {
            // brand img
            var $navbarBrand = $(".navbar-brand");
            var img = new Image();
            img.alt = "${appName}";
            // 1.声明事件
            img.onload = function () {
                if (img.height > 0) {
                    $navbarBrand.html(img);
                }
            };
            // 2.加载图片
            img.src = "${assetPath(src: "skin/${skinName}/logo.png")}";
        });
    </script>
    <%--suppress JSValidateTypes --%>
    <script type="text/javascript">
        $(function () {
            // user authc menu
            var $navbarRight = $(".navbar-right");
            //need suppress JSValidateTypes
            var $loginBtn = $navbarRight.find(".glyphicon-log-in").parent();
            var $logoutBtn = $navbarRight.find(".glyphicon-log-out").parent();
            if ("${userName}" != "${SystemUserName.Anonymous.name()}") {
                $navbarRight.find(".glyphicon-user").parents("li:hidden").removeClass("hidden");
                $logoutBtn.parent("li").removeClass("hidden");
            } else {
                $loginBtn.parent("li").removeClass("hidden");
            }
        });
    </script>
    <g:pageProperty name="page.script"/>
</content>
</body>
</html>
</g:applyLayout>